﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.BreedingHistory.Domain.BreedingHistoryDto;
using S.BreedingHistory.Read.Api.Application.Command;
using S.BreedingHistory.Read.Api.Dto;

namespace S.BreedingHistory.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedingHistoryReadController : BaseController
    {
        private readonly IMediator mediator;

        public BreedingHistoryReadController(MySqlDbContext _db, IMediator mediator) : base(_db)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 种母历史记录的列表显示
        /// </summary>
        /// <param name="breedingHistoryListCommand"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<BreedHistoryPageListDto> GetBreedingHistoryList(BreedingHistoryListCommand breeding)
        {
            return await mediator.Send(breeding);
        }
        /// <summary>
        /// 种母历史记录的反填
        /// </summary>
        /// <param name="breedingHistoryGetByIdCommand"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<BreedingHistoryListDto> GetBreedingHistoryById(BreedingHistoryGetByIdCommand breedingHistoryGetByIdCommand)
        {
            return await  mediator.Send(breedingHistoryGetByIdCommand);
        }
        /// <summary>
        /// 通过种母Id查询种母档案卡
        /// </summary>
        /// <param name="breedFileCardGetByIdCommand"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<List<FileCardDto>> GetBreedFileCard(BreedFileCardGetByIdCommand breedFileCardGetByIdCommand)
        {
            return await mediator.Send(breedFileCardGetByIdCommand);
        }
        [Authorize]
        [HttpGet]
        public IActionResult IgetTest()
        {
            return Ok("李玺的服务");
        }
        /// <summary>
        /// 通过种母历史记录主键获取种母信息
        /// </summary>
        /// <param name="breeding"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<BreedingHistoryListDto> GetBreedingHistoryByPId(BreedingHistoryByPIdCommand breeding)
        {
            return await mediator.Send(breeding);
        }
        /// <summary>
        /// 通过种母耳号查找种母最新记录
        /// </summary>
        /// <param name="breeding"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<BreedingHistoryListDto> GetNewBreedingHistoryByPId(BreedingHistoryByEarTagCommand breeding)
        {
            return await mediator.Send(breeding);
        }
    }
}
